package cn.lystudio.rohmtimeopwide_background_v11.controller.appApi;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.lystudio.rohmtimeopwide_background_v11.entity.po.MaintsItemPO;
import cn.lystudio.rohmtimeopwide_background_v11.service.MaintsItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app-api/maintsitem")
@CrossOrigin
@SaIgnore
@Slf4j
public class AppMaintsItemController {
    private MaintsItemService maintsItemService;

    @Autowired
    @Lazy
    public void setMaintsItemService(MaintsItemService maintsItemService) {
        this.maintsItemService = maintsItemService;
    }

    @GetMapping("/getMaintsItemListByMachineNo")
    public SaResult getMaintsItemListByMachineNo(@RequestParam("machineNo") String machineNo){
        List<MaintsItemPO> maintsItemList = maintsItemService.getMaintsItemListByMachineNo(machineNo);
        if(CollUtil.isEmpty(maintsItemList)) return SaResult.error("没有操作项");
        return SaResult.data(maintsItemList);
    }
    @GetMapping("/getMaintsItemByOpItemNameAndMachineNo")
    public SaResult getMaintsItemByOpItemNameAndMachineNo(String opItemName,String machineNo){
        MaintsItemPO maintsItemPO = maintsItemService.getMaintsItemByOpItemNameAndMachineNo(opItemName, machineNo);
        if(ObjectUtil.isEmpty(maintsItemPO)) return SaResult.error("设置值已变更,无法修改数据");
        return SaResult.data(maintsItemPO);
    }


}
